package gfyx_oppty_service_remote

import (
	"context"
	"git.mycaigou.com/gfyx/common/rpc_client"
	"git.mycaigou.com/gfyx/micro-gfyx-user-service/infrastructure/common/constants"
	micro_gfyx_oppty_service "git.mycaigou.com/gfyx/micro-gfyx-user-service/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/base"
)

type gfyxOpptyServiceRepository struct {
}

// NewGfyxOpptyServiceRepository 构造函数
func NewGfyxOpptyServiceRepository() GfyxOpptyServiceRepositoryIface {
	return &gfyxOpptyServiceRepository{}
}

// SaveTenantProfit 保存租户权益
func (r *gfyxOpptyServiceRepository) SaveTenantProfit(ctx context.Context, request *micro_gfyx_oppty_service.SaveTenantProfitRequest) (*micro_gfyx_oppty_service.SaveTenantProfitResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MicroGfyxOpptyService)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := micro_gfyx_oppty_service.NewProfitServiceClient(conn)
	res, err := client.SaveTenantProfit(ctx, request)
	if err != nil {
		return nil, err
	}

	return res, nil
}

// UpdateAdminPassword 更新admin密码
func (r *gfyxOpptyServiceRepository) UpdateAdminPassword(ctx context.Context, request *micro_gfyx_oppty_service.UpdateAdminPasswordRequest) (*micro_gfyx_oppty_service.UpdateAdminPasswordResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MicroGfyxOpptyService)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := micro_gfyx_oppty_service.NewBaseUserServiceClient(conn)
	res, err := client.UpdateAdminPassword(ctx, request)
	if err != nil {
		return nil, err
	}

	return res, nil
}
